import type { ProductionStatus } from '../../basic-archives/production/production-status.enum';
import type { PagedAndSortedResultRequestDto } from '@abp/ng.core';
import type { SupplyDemandType } from './supply-demand-type.enum';

export interface DailyBalanceDto {
  date?: string;
  currentStock: number;
  demandQuantity: number;
  supplyQuantity: number;
  projectedEndingStock: number;
  isShortage: boolean;
  shortageQuantity?: number;
}

export interface DemandOrderDto {
  docNo?: string;
  docType?: string;
  productionStatus: ProductionStatus;
  tradeType: number;
  seiban?: string;
  demandCode?: string;
  productItemMasterId?: string;
  productItemCode?: string;
  productItemName?: string;
  productItemSpec?: string;
  productQuantity: number;
  complatedQuantity: number;
  startDate?: string;
  adjustedStartDate?: string;
  itemMasterId?: string;
  itemCode?: string;
  itemName?: string;
  itemSpec?: string;
  quantity: number;
  adjustedQuantity: number;
  issuedQuantity: number;
  kitCount?: number;
  kitStatus?: string;
  memo?: string;
  children: DemandOrderDto[];
  occupiedRecords: OccupiedRecordDto[];
}

export interface GetDemandOrderPagedInput extends PagedAndSortedResultRequestDto {
  forceRefresh: boolean;
  excludedKitStatuses: string[];
}

export interface GetMaterialBalanceInput extends PagedAndSortedResultRequestDto {
  cutoffDate?: string;
  itemCode?: string;
  itemMasterIds: string[];
  includeSafetyStockWarning: boolean;
  onlyShowShortage: boolean;
  forceRefresh: boolean;
}

export interface KitInput {
  allocationType?: string;
}

export interface LoadSupplyDemandDataInput {
  cutoffDate?: string;
}

export interface MaterialBalanceAnalysisDto {
  itemMasterId?: string;
  itemCode?: string;
  itemName?: string;
  itemSpec?: string;
  uom?: string;
  initialStock: number;
  totalDemandQuantity: number;
  totalSupplyQuantity: number;
  projectedEndingStock: number;
  safetyStock?: number;
  minOrderQuantity?: number;
  withinPeriodStock: number;
  withinPeriodTotalSupply: number;
  withinPeriodTotalDemand: number;
  outOfPeriodStock: number;
  outOfPeriodTotalSupply: number;
  outOfPeriodTotalDemand: number;
  isWithinPeriodShortage: boolean;
  withinPeriodMaxShortageQuantity?: number;
  isOutOfPeriodShortage: boolean;
  outOfPeriodMaxShortageQuantity?: number;
  dailyBalances: DailyBalanceDto[];
  supplyDemandRecords: SupplyDemandRecordDto[];
}

export interface OccupiedRecordDto {
  demandOrderDocNo?: string;
  demandOrderDocType?: string;
  supplyOrderDocNo?: string;
  supplyOrderDocType?: string;
  demandProductDocNo?: string;
  demandProductItemMasterId?: string;
  demandProductItemCode?: string;
  demandProductItemName?: string;
  demandProductItemSpec?: string;
  itemMasterId?: string;
  itemCode?: string;
  itemName?: string;
  itemSpec?: string;
  occupiedQuantity: number;
}

export interface SupplyDemandRecordDto {
  type: SupplyDemandType;
  docNo?: string;
  docType?: string;
  docTypeName?: string;
  itemCode?: string;
  itemName?: string;
  itemSpec?: string;
  businessDate?: string;
  quantity: number;
  completedQuantity: number;
  pendingQuantity: number;
  status?: string;
  seiban?: string;
  demandCode?: string;
  remark?: string;
  sourceId?: string;
  sourceLineId?: string;
}

export interface UpdateDemandOrderInput {
  docNo?: string;
  docType?: string;
  demandOrder: DemandOrderDto;
}
